/*
 * Copyright 2010-2012 Susanta Tewari. <freecode4susant@users.sourceforge.net>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package javautil.regex;

import javautil.io.LogUtil;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Susanta Tewari <statsusant@yahoo.com>
 */
public class RegExUtil {

    public static void main(String[] args) {

        String regex    = "[\\s-(),._\\d]";
        String testStr1 = "12This,is_(Susanta.)_001-Tewari";
        String testStr2 = "Qayamat Se Qayamat Tak (1988)";

        LogUtil.print(parseWords(testStr2, regex));
    }

    /**
     * Method description
     *
     * @param sentence description
     * @param regex description
     *
     * @return description
     */
    private static String[] parseWords(String sentence, String regex) {

        String[] rawWords  = sentence.split(regex);
        List<String> words = new ArrayList<>();

        for (String rawWord : rawWords) {

            if (rawWord.length() > 0) {
                words.add(rawWord);
            }
        }

        return words.toArray(new String[0]);
    }
}
